Characterising the sensor response curve

There are three parameters that contribute to the signal: the gain on the amplifier, the exposure or shutter time and the actual flux of light. In this section I’ll explore these parameters with the goal of achieving a stable signal that responds linearly to changes in light conditions.

Light and exposure time:

The first thing to do is to find saturating conditions that allow for subsequent fine tuning. The first experiment consisted on measuring light at increasing exposure times with 10 ms increments, from 10 to 970 ms. This was done with full light intensity and a gain of 1 (default). From visual inspection already it can be seen that between 40 ms and 50 ms the image starts to show burned pixels, thus to saturate.

40ms.

50 ms.

970 ms.

This is confirmed when the spectra are ploted according to the exposure time:

files = paste0("Data/SingalVsTime Long/",list.files("Data/SingalVsTime Long/"))[c(-1,-99)]
expTimes = files %>% str_extract(pattern = regex("[:digit:]+"))
spectra = map(files,py$get_spectrum) %>% bind_cols()
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
## • `` -> `...19`
## • `` -> `...20`
## • `` -> `...21`
## • `` -> `...22`
## • `` -> `...23`
## • `` -> `...24`
## • `` -> `...25`
## • `` -> `...26`
## • `` -> `...27`
## • `` -> `...28`
## • `` -> `...29`
## • `` -> `...30`
## • `` -> `...31`
## • `` -> `...32`
## • `` -> `...33`
## • `` -> `...34`
## • `` -> `...35`
## • `` -> `...36`
## • `` -> `...37`
## • `` -> `...38`
## • `` -> `...39`
## • `` -> `...40`
## • `` -> `...41`
## • `` -> `...42`
## • `` -> `...43`
## • `` -> `...44`
## • `` -> `...45`
## • `` -> `...46`
## • `` -> `...47`
## • `` -> `...48`
## • `` -> `...49`
## • `` -> `...50`
## • `` -> `...51`
## • `` -> `...52`
## • `` -> `...53`
## • `` -> `...54`
## • `` -> `...55`
## • `` -> `...56`
## • `` -> `...57`
## • `` -> `...58`
## • `` -> `...59`
## • `` -> `...60`
## • `` -> `...61`
## • `` -> `...62`
## • `` -> `...63`
## • `` -> `...64`
## • `` -> `...65`
## • `` -> `...66`
## • `` -> `...67`
## • `` -> `...68`
## • `` -> `...69`
## • `` -> `...70`
## • `` -> `...71`
## • `` -> `...72`
## • `` -> `...73`
## • `` -> `...74`
## • `` -> `...75`
## • `` -> `...76`
## • `` -> `...77`
## • `` -> `...78`
## • `` -> `...79`
## • `` -> `...80`
## • `` -> `...81`
## • `` -> `...82`
## • `` -> `...83`
## • `` -> `...84`
## • `` -> `...85`
## • `` -> `...86`
## • `` -> `...87`
## • `` -> `...88`
## • `` -> `...89`
## • `` -> `...90`
## • `` -> `...91`
## • `` -> `...92`
## • `` -> `...93`
## • `` -> `...94`
## • `` -> `...95`
## • `` -> `...96`
## • `` -> `...97`
spectra = t(spectra) %>% as_tibble()
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
## Using compatibility `.name_repair`.
colnames(spectra) = 1:512
spectra$expTimes = expTimes
gathered = spectra %>% gather("pixel","signal",1:512)
gathered$expTimes = gathered$expTimes %>% as.numeric()
gathered$pixel = gathered$pixel %>% as.numeric()
ggplot(gathered,aes(pixel,signal)) + geom_line() + transition_states(expTimes) + labs(title = "Exposure time: {closest_state} us") 

Now that the saturating conditions were found, the response of the signal to variations in the exposure time can be explored. This was done by measuring the signal at a fixed gain of 1 and full light intensity at 1 ms intervals from 1 to 49 ms.

files = paste0("Data/SignalVsTime2/",list.files("Data/SignalVsTime2/"))#[-1]
expTimes = files %>% str_extract(pattern = regex("[:digit:]+(?=.d)")) %>% as.numeric()
spectra = map(files,py$get_spectrum) %>% bind_cols()
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
## • `` -> `...19`
## • `` -> `...20`
## • `` -> `...21`
## • `` -> `...22`
## • `` -> `...23`
## • `` -> `...24`
## • `` -> `...25`
## • `` -> `...26`
## • `` -> `...27`
## • `` -> `...28`
## • `` -> `...29`
## • `` -> `...30`
## • `` -> `...31`
## • `` -> `...32`
## • `` -> `...33`
## • `` -> `...34`
## • `` -> `...35`
## • `` -> `...36`
## • `` -> `...37`
## • `` -> `...38`
## • `` -> `...39`
## • `` -> `...40`
## • `` -> `...41`
## • `` -> `...42`
## • `` -> `...43`
## • `` -> `...44`
## • `` -> `...45`
## • `` -> `...46`
## • `` -> `...47`
## • `` -> `...48`
## • `` -> `...49`
spectra = t(spectra) %>% as_tibble()
colnames(spectra) = 1:512
spectra$expTimes = expTimes
gathered = spectra %>% gather("pixel","signal",1:512)
gathered$expTimes = gathered$expTimes %>% as.numeric()
gathered$pixel = gathered$pixel %>% as.numeric()
ggplot(gathered,aes(pixel,signal)) + geom_line() + transition_states(expTimes) + labs(title = "Exposure time: {closest_state} us") 

files = paste0("Data/PWM and time/20000/",list.files("Data/PWM and time/20000/"))
percLight = files %>% str_extract(pattern = regex("(?<=_)([:digit:].[:digit:]+)")) %>% as.numeric()
spectra = map(files,py$get_spectrum) %>% bind_cols()
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
spectra = t(spectra) %>% as_tibble()
colnames(spectra) = 1:512
spectra$percLight = percLight
gathered = spectra %>% gather("pixel","signal",1:512)
gathered$pixel = gathered$pixel %>% as.numeric()
ggplot(gathered,aes(pixel,signal)) + geom_line() + transition_states(percLight*100) + labs(title = "Exposure time: {closest_state} %") 

ggplot(gathered, aes(pixel,signal,colour = percLight %>% as.factor())) + geom_line()

files = paste0("Data/PWM and time/40000/",list.files("Data/PWM and time/40000/"))
percLight = files %>% str_extract(pattern = regex("(?<=_)([:digit:].[:digit:]+)")) %>% as.numeric()
spectra = map(files,py$get_spectrum) %>% bind_cols()
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
spectra = t(spectra) %>% as_tibble()
colnames(spectra) = 1:512
spectra$percLight = percLight
gathered = spectra %>% gather("pixel","signal",1:512)
gathered$pixel = gathered$pixel %>% as.numeric()
ggplot(gathered, aes(pixel %>% as.numeric(),signal,colour = percLight %>% as.factor())) + geom_line()

files = paste0("Data/SignalVsTimeVsGain/",list.files("Data/SignalVsTimeVsGain/"))
Gains = files %>% str_extract(pattern = regex("[:digit:]")) %>% as.numeric()
expTimes = files %>% str_extract(pattern = regex("[:digit:]+(?=.d)")) %>% as.numeric()
spectra = map(files,py$get_spectrum) %>% bind_cols()
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
## • `` -> `...19`
## • `` -> `...20`
## • `` -> `...21`
## • `` -> `...22`
## • `` -> `...23`
## • `` -> `...24`
## • `` -> `...25`
## • `` -> `...26`
## • `` -> `...27`
## • `` -> `...28`
## • `` -> `...29`
## • `` -> `...30`
## • `` -> `...31`
## • `` -> `...32`
## • `` -> `...33`
## • `` -> `...34`
spectra = t(spectra) %>% as_tibble()
colnames(spectra) = 1:512
spectra$expTimes = expTimes
spectra$gains = Gains
spectra = spectra[spectra$expTimes != 0,]
gathered = spectra %>% gather("pixel","signal",1:512)
gathered$expTimes = gathered$expTimes %>% as.numeric()
gathered$pixel = gathered$pixel %>% as.numeric()
gathered$gains = gathered$gains %>% as.factor()
ggplot(gathered,aes(pixel,signal)) + geom_line() + facet_wrap(~gains) + transition_states(expTimes) + labs(title = "Exposure time: {closest_state} us") 

ggplot(gathered[gathered$pixel == 200,],aes(expTimes,signal)) + geom_line() + facet_wrap(~gains)

files = paste0("Data/rep/",list.files("Data/rep/"))#[-1]
expTimes = files %>% str_extract(pattern = regex("[:digit:]+(?=.d)")) %>% as.numeric()
spectra = map(files,py$get_spectrum) %>% bind_cols()
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
## • `` -> `...19`
## • `` -> `...20`
## • `` -> `...21`
## • `` -> `...22`
## • `` -> `...23`
## • `` -> `...24`
## • `` -> `...25`
## • `` -> `...26`
## • `` -> `...27`
## • `` -> `...28`
## • `` -> `...29`
## • `` -> `...30`
## • `` -> `...31`
## • `` -> `...32`
## • `` -> `...33`
## • `` -> `...34`
## • `` -> `...35`
## • `` -> `...36`
## • `` -> `...37`
## • `` -> `...38`
## • `` -> `...39`
## • `` -> `...40`
## • `` -> `...41`
## • `` -> `...42`
## • `` -> `...43`
## • `` -> `...44`
## • `` -> `...45`
## • `` -> `...46`
## • `` -> `...47`
## • `` -> `...48`
## • `` -> `...49`
## • `` -> `...50`
## • `` -> `...51`
## • `` -> `...52`
## • `` -> `...53`
## • `` -> `...54`
## • `` -> `...55`
## • `` -> `...56`
## • `` -> `...57`
## • `` -> `...58`
## • `` -> `...59`
## • `` -> `...60`
## • `` -> `...61`
## • `` -> `...62`
## • `` -> `...63`
## • `` -> `...64`
## • `` -> `...65`
## • `` -> `...66`
## • `` -> `...67`
## • `` -> `...68`
## • `` -> `...69`
## • `` -> `...70`
## • `` -> `...71`
## • `` -> `...72`
## • `` -> `...73`
## • `` -> `...74`
## • `` -> `...75`
## • `` -> `...76`
## • `` -> `...77`
## • `` -> `...78`
## • `` -> `...79`
## • `` -> `...80`
## • `` -> `...81`
## • `` -> `...82`
## • `` -> `...83`
## • `` -> `...84`
## • `` -> `...85`
## • `` -> `...86`
## • `` -> `...87`
## • `` -> `...88`
## • `` -> `...89`
## • `` -> `...90`
## • `` -> `...91`
## • `` -> `...92`
## • `` -> `...93`
## • `` -> `...94`
## • `` -> `...95`
## • `` -> `...96`
## • `` -> `...97`
## • `` -> `...98`
## • `` -> `...99`
## • `` -> `...100`
spectra = t(spectra) %>% as_tibble()
colnames(spectra) = 1:512
spectra$expTimes = expTimes
gathered = spectra %>% gather("pixel","signal",1:512)
gathered$expTimes = gathered$expTimes %>% as.numeric()
gathered$pixel = gathered$pixel %>% as.numeric()
ggplot(gathered,aes(pixel,signal)) + geom_line() + transition_states(expTimes) + labs(title = "Exposure time: {closest_state} us") 

(apply(spectra, 2, sd)/colMeans(spectra) )%>% .[1:512] %>% plot()

library(rjson)

Results = jsonlite::read_json("Data/results.json")
Spectra = Results %>% map(function(x){x[["spectrum"]]})
Tags = Results %>% map(function(x){x[["tag"]]})
Results[[1]][["spectrum"]]
## [[1]]
## [1] 3.779556
## 
## [[2]]
## [1] 3.652889
## 
## [[3]]
## [1] 2.144
## 
## [[4]]
## [1] 3.101778
## 
## [[5]]
## [1] 2.289333
## 
## [[6]]
## [1] 2.428
## 
## [[7]]
## [1] 4.011556
## 
## [[8]]
## [1] 3.876
## 
## [[9]]
## [1] 2.946222
## 
## [[10]]
## [1] 4.448444
## 
## [[11]]
## [1] 2.780889
## 
## [[12]]
## [1] 2.538667
## 
## [[13]]
## [1] 5.029778
## 
## [[14]]
## [1] 4.083556
## 
## [[15]]
## [1] 3.008
## 
## [[16]]
## [1] 3.411111
## 
## [[17]]
## [1] 3.448
## 
## [[18]]
## [1] 3.327556
## 
## [[19]]
## [1] 3.588444
## 
## [[20]]
## [1] 4.388444
## 
## [[21]]
## [1] 5.192889
## 
## [[22]]
## [1] 2.150222
## 
## [[23]]
## [1] 4.414667
## 
## [[24]]
## [1] 5.249333
## 
## [[25]]
## [1] 4.642222
## 
## [[26]]
## [1] 4.910222
## 
## [[27]]
## [1] 4.735111
## 
## [[28]]
## [1] 3.451556
## 
## [[29]]
## [1] 4.879556
## 
## [[30]]
## [1] 4.297778
## 
## [[31]]
## [1] 4.775556
## 
## [[32]]
## [1] 3.443556
## 
## [[33]]
## [1] 4.874667
## 
## [[34]]
## [1] 4.043556
## 
## [[35]]
## [1] 4.321778
## 
## [[36]]
## [1] 3.921778
## 
## [[37]]
## [1] 5.722667
## 
## [[38]]
## [1] 6.711111
## 
## [[39]]
## [1] 3.853778
## 
## [[40]]
## [1] 4.217333
## 
## [[41]]
## [1] 5.319111
## 
## [[42]]
## [1] 3.832889
## 
## [[43]]
## [1] 5.451556
## 
## [[44]]
## [1] 6.640444
## 
## [[45]]
## [1] 7.134222
## 
## [[46]]
## [1] 6.514222
## 
## [[47]]
## [1] 5.905333
## 
## [[48]]
## [1] 6.337333
## 
## [[49]]
## [1] 8.891111
## 
## [[50]]
## [1] 6.398222
## 
## [[51]]
## [1] 5.652889
## 
## [[52]]
## [1] 4.756
## 
## [[53]]
## [1] 7.154667
## 
## [[54]]
## [1] 9.292
## 
## [[55]]
## [1] 6.461778
## 
## [[56]]
## [1] 6.205778
## 
## [[57]]
## [1] 8.604444
## 
## [[58]]
## [1] 9.536
## 
## [[59]]
## [1] 6.928889
## 
## [[60]]
## [1] 8.984
## 
## [[61]]
## [1] 9.592
## 
## [[62]]
## [1] 7.057778
## 
## [[63]]
## [1] 7.102667
## 
## [[64]]
## [1] 8.797333
## 
## [[65]]
## [1] 10.79067
## 
## [[66]]
## [1] 9.377778
## 
## [[67]]
## [1] 9.034667
## 
## [[68]]
## [1] 9.888444
## 
## [[69]]
## [1] 9.393778
## 
## [[70]]
## [1] 8.493333
## 
## [[71]]
## [1] 11.50844
## 
## [[72]]
## [1] 7.865778
## 
## [[73]]
## [1] 11.28133
## 
## [[74]]
## [1] 10.74178
## 
## [[75]]
## [1] 11.72667
## 
## [[76]]
## [1] 13.06844
## 
## [[77]]
## [1] 11.89867
## 
## [[78]]
## [1] 16.00444
## 
## [[79]]
## [1] 11.28533
## 
## [[80]]
## [1] 16.54044
## 
## [[81]]
## [1] 15.14667
## 
## [[82]]
## [1] 16.34667
## 
## [[83]]
## [1] 56.21422
## 
## [[84]]
## [1] 9.326667
## 
## [[85]]
## [1] 13.41244
## 
## [[86]]
## [1] 19.74667
## 
## [[87]]
## [1] 14.88222
## 
## [[88]]
## [1] 17.77022
## 
## [[89]]
## [1] 15.87022
## 
## [[90]]
## [1] 19.23822
## 
## [[91]]
## [1] 17.83244
## 
## [[92]]
## [1] 17.56089
## 
## [[93]]
## [1] 17.75422
## 
## [[94]]
## [1] 20.09289
## 
## [[95]]
## [1] 18.01956
## 
## [[96]]
## [1] 16.76933
## 
## [[97]]
## [1] 16.968
## 
## [[98]]
## [1] 16.66089
## 
## [[99]]
## [1] 18.20267
## 
## [[100]]
## [1] 16.76667
## 
## [[101]]
## [1] 17.14444
## 
## [[102]]
## [1] 15.76222
## 
## [[103]]
## [1] 19.51467
## 
## [[104]]
## [1] 19.96622
## 
## [[105]]
## [1] 24.55778
## 
## [[106]]
## [1] 20.24622
## 
## [[107]]
## [1] 22.24222
## 
## [[108]]
## [1] 22.00311
## 
## [[109]]
## [1] 24.74978
## 
## [[110]]
## [1] 21.90044
## 
## [[111]]
## [1] 19.85289
## 
## [[112]]
## [1] 23.676
## 
## [[113]]
## [1] 22.95378
## 
## [[114]]
## [1] 25.04889
## 
## [[115]]
## [1] 25.49111
## 
## [[116]]
## [1] 25.67956
## 
## [[117]]
## [1] 36.98489
## 
## [[118]]
## [1] 25.58356
## 
## [[119]]
## [1] 23.12489
## 
## [[120]]
## [1] 25.70267
## 
## [[121]]
## [1] 29.42533
## 
## [[122]]
## [1] 26.89867
## 
## [[123]]
## [1] 29.71956
## 
## [[124]]
## [1] 25.52044
## 
## [[125]]
## [1] 22.75333
## 
## [[126]]
## [1] 34.02933
## 
## [[127]]
## [1] 31.076
## 
## [[128]]
## [1] 34.524
## 
## [[129]]
## [1] 31.27644
## 
## [[130]]
## [1] 31.29556
## 
## [[131]]
## [1] 41.00311
## 
## [[132]]
## [1] 32.26756
## 
## [[133]]
## [1] 34.32622
## 
## [[134]]
## [1] 32.74933
## 
## [[135]]
## [1] 31.22044
## 
## [[136]]
## [1] 33.78489
## 
## [[137]]
## [1] 38.85333
## 
## [[138]]
## [1] 38.89111
## 
## [[139]]
## [1] 36.52044
## 
## [[140]]
## [1] 32.28178
## 
## [[141]]
## [1] 34.52133
## 
## [[142]]
## [1] 32.75244
## 
## [[143]]
## [1] 30.75911
## 
## [[144]]
## [1] 39.016
## 
## [[145]]
## [1] 34.508
## 
## [[146]]
## [1] 35.68222
## 
## [[147]]
## [1] 43.20222
## 
## [[148]]
## [1] 55.68889
## 
## [[149]]
## [1] 63.50622
## 
## [[150]]
## [1] 50.948
## 
## [[151]]
## [1] 44.28311
## 
## [[152]]
## [1] 45.59511
## 
## [[153]]
## [1] 47.01556
## 
## [[154]]
## [1] 51.91022
## 
## [[155]]
## [1] 43.48089
## 
## [[156]]
## [1] 46.12178
## 
## [[157]]
## [1] 54.18933
## 
## [[158]]
## [1] 45.18978
## 
## [[159]]
## [1] 48.88933
## 
## [[160]]
## [1] 43.91778
## 
## [[161]]
## [1] 47.01644
## 
## [[162]]
## [1] 49.80489
## 
## [[163]]
## [1] 43.61733
## 
## [[164]]
## [1] 47.74578
## 
## [[165]]
## [1] 60.77244
## 
## [[166]]
## [1] 52.36267
## 
## [[167]]
## [1] 45.48356
## 
## [[168]]
## [1] 43.97644
## 
## [[169]]
## [1] 49.55022
## 
## [[170]]
## [1] 46.25733
## 
## [[171]]
## [1] 48.68133
## 
## [[172]]
## [1] 40.58267
## 
## [[173]]
## [1] 44.36444
## 
## [[174]]
## [1] 51.53556
## 
## [[175]]
## [1] 55.34889
## 
## [[176]]
## [1] 59.81778
## 
## [[177]]
## [1] 50.21778
## 
## [[178]]
## [1] 52.77822
## 
## [[179]]
## [1] 51.53644
## 
## [[180]]
## [1] 56.03822
## 
## [[181]]
## [1] 74.68
## 
## [[182]]
## [1] 69.52578
## 
## [[183]]
## [1] 55.27822
## 
## [[184]]
## [1] 51.25644
## 
## [[185]]
## [1] 57.85422
## 
## [[186]]
## [1] 82.41156
## 
## [[187]]
## [1] 67.27244
## 
## [[188]]
## [1] 66.30622
## 
## [[189]]
## [1] 64.72978
## 
## [[190]]
## [1] 56.51422
## 
## [[191]]
## [1] 49.30578
## 
## [[192]]
## [1] 66.80311
## 
## [[193]]
## [1] 66.68978
## 
## [[194]]
## [1] 62.57689
## 
## [[195]]
## [1] 74.70267
## 
## [[196]]
## [1] 58.47244
## 
## [[197]]
## [1] 59.28444
## 
## [[198]]
## [1] 56.97511
## 
## [[199]]
## [1] 52.30089
## 
## [[200]]
## [1] 58.48889
## 
## [[201]]
## [1] 74.10978
## 
## [[202]]
## [1] 72.22889
## 
## [[203]]
## [1] 54.94489
## 
## [[204]]
## [1] 62.89778
## 
## [[205]]
## [1] 76.44
## 
## [[206]]
## [1] 70.79867
## 
## [[207]]
## [1] 71.232
## 
## [[208]]
## [1] 62.23689
## 
## [[209]]
## [1] 67.55956
## 
## [[210]]
## [1] 60.66533
## 
## [[211]]
## [1] 61.89022
## 
## [[212]]
## [1] 59.22933
## 
## [[213]]
## [1] 69.29689
## 
## [[214]]
## [1] 71.30933
## 
## [[215]]
## [1] 63.75956
## 
## [[216]]
## [1] 63.312
## 
## [[217]]
## [1] 76.27689
## 
## [[218]]
## [1] 77.676
## 
## [[219]]
## [1] 71.39733
## 
## [[220]]
## [1] 66.98711
## 
## [[221]]
## [1] 96.46533
## 
## [[222]]
## [1] 79.28889
## 
## [[223]]
## [1] 60.36844
## 
## [[224]]
## [1] 56.26089
## 
## [[225]]
## [1] 59.95867
## 
## [[226]]
## [1] 62.25733
## 
## [[227]]
## [1] 64.88756
## 
## [[228]]
## [1] 63.208
## 
## [[229]]
## [1] 56.86356
## 
## [[230]]
## [1] 65.46356
## 
## [[231]]
## [1] 69.63911
## 
## [[232]]
## [1] 82.06933
## 
## [[233]]
## [1] 66.76356
## 
## [[234]]
## [1] 85.30711
## 
## [[235]]
## [1] 57.26711
## 
## [[236]]
## [1] 58.13911
## 
## [[237]]
## [1] 50.73378
## 
## [[238]]
## [1] 48.11022
## 
## [[239]]
## [1] 61.93067
## 
## [[240]]
## [1] 56.44933
## 
## [[241]]
## [1] 59.74622
## 
## [[242]]
## [1] 58.24489
## 
## [[243]]
## [1] 66.664
## 
## [[244]]
## [1] 60.89956
## 
## [[245]]
## [1] 58.73244
## 
## [[246]]
## [1] 52.84222
## 
## [[247]]
## [1] 56.14622
## 
## [[248]]
## [1] 55.41022
## 
## [[249]]
## [1] 49.27156
## 
## [[250]]
## [1] 54.30222
## 
## [[251]]
## [1] 68.688
## 
## [[252]]
## [1] 55.94222
## 
## [[253]]
## [1] 60.11244
## 
## [[254]]
## [1] 53.95778
## 
## [[255]]
## [1] 50.64133
## 
## [[256]]
## [1] 49.90933
## 
## [[257]]
## [1] 56.20578
## 
## [[258]]
## [1] 50.85111
## 
## [[259]]
## [1] 47.74533
## 
## [[260]]
## [1] 46.93111
## 
## [[261]]
## [1] 38.47156
## 
## [[262]]
## [1] 38.49956
## 
## [[263]]
## [1] 36.42178
## 
## [[264]]
## [1] 45.81422
## 
## [[265]]
## [1] 45.99333
## 
## [[266]]
## [1] 56.192
## 
## [[267]]
## [1] 53.53333
## 
## [[268]]
## [1] 47.37867
## 
## [[269]]
## [1] 40.28622
## 
## [[270]]
## [1] 51.07378
## 
## [[271]]
## [1] 46.61422
## 
## [[272]]
## [1] 39.36444
## 
## [[273]]
## [1] 36.81778
## 
## [[274]]
## [1] 39.88356
## 
## [[275]]
## [1] 32.76
## 
## [[276]]
## [1] 35.13644
## 
## [[277]]
## [1] 39.99511
## 
## [[278]]
## [1] 38.236
## 
## [[279]]
## [1] 31.90533
## 
## [[280]]
## [1] 34.01733
## 
## [[281]]
## [1] 39.07644
## 
## [[282]]
## [1] 48.12667
## 
## [[283]]
## [1] 37.23156
## 
## [[284]]
## [1] 32.61467
## 
## [[285]]
## [1] 30.53378
## 
## [[286]]
## [1] 37.52356
## 
## [[287]]
## [1] 38.24711
## 
## [[288]]
## [1] 27.49644
## 
## [[289]]
## [1] 31.75867
## 
## [[290]]
## [1] 35.61289
## 
## [[291]]
## [1] 29.28578
## 
## [[292]]
## [1] 28.23022
## 
## [[293]]
## [1] 26.63556
## 
## [[294]]
## [1] 29.76889
## 
## [[295]]
## [1] 33.66089
## 
## [[296]]
## [1] 31.51244
## 
## [[297]]
## [1] 24.70844
## 
## [[298]]
## [1] 27.848
## 
## [[299]]
## [1] 28.41778
## 
## [[300]]
## [1] 26.61689
## 
## [[301]]
## [1] 32.44978
## 
## [[302]]
## [1] 31.00044
## 
## [[303]]
## [1] 27.24933
## 
## [[304]]
## [1] 25.71911
## 
## [[305]]
## [1] 29.86267
## 
## [[306]]
## [1] 23.79467
## 
## [[307]]
## [1] 24.69733
## 
## [[308]]
## [1] 25.79333
## 
## [[309]]
## [1] 23.52222
## 
## [[310]]
## [1] 25.49289
## 
## [[311]]
## [1] 20.48533
## 
## [[312]]
## [1] 40.81644
## 
## [[313]]
## [1] 19.03956
## 
## [[314]]
## [1] 27.25689
## 
## [[315]]
## [1] 24.79956
## 
## [[316]]
## [1] 25.68133
## 
## [[317]]
## [1] 21.89867
## 
## [[318]]
## [1] 20.83022
## 
## [[319]]
## [1] 19.82533
## 
## [[320]]
## [1] 19.248
## 
## [[321]]
## [1] 24.87644
## 
## [[322]]
## [1] 18.292
## 
## [[323]]
## [1] 19.25244
## 
## [[324]]
## [1] 15.84178
## 
## [[325]]
## [1] 16.77511
## 
## [[326]]
## [1] 19.38089
## 
## [[327]]
## [1] 15.24578
## 
## [[328]]
## [1] 16.39778
## 
## [[329]]
## [1] 17.376
## 
## [[330]]
## [1] 15.33422
## 
## [[331]]
## [1] 22.29689
## 
## [[332]]
## [1] 15.936
## 
## [[333]]
## [1] 15.504
## 
## [[334]]
## [1] 15.85733
## 
## [[335]]
## [1] 12.40311
## 
## [[336]]
## [1] 13.18044
## 
## [[337]]
## [1] 14.28667
## 
## [[338]]
## [1] 10.19956
## 
## [[339]]
## [1] 7.916889
## 
## [[340]]
## [1] 18.53467
## 
## [[341]]
## [1] 12.02533
## 
## [[342]]
## [1] 10.49156
## 
## [[343]]
## [1] 12.77289
## 
## [[344]]
## [1] 9.085333
## 
## [[345]]
## [1] 9.625778
## 
## [[346]]
## [1] 11.708
## 
## [[347]]
## [1] 8.984444
## 
## [[348]]
## [1] 7.338222
## 
## [[349]]
## [1] 8.974667
## 
## [[350]]
## [1] 7.589778
## 
## [[351]]
## [1] 7.484
## 
## [[352]]
## [1] 9.192444
## 
## [[353]]
## [1] 8.585333
## 
## [[354]]
## [1] 8.738222
## 
## [[355]]
## [1] 7.088
## 
## [[356]]
## [1] 9.505333
## 
## [[357]]
## [1] 10.70444
## 
## [[358]]
## [1] 7.603111
## 
## [[359]]
## [1] 7.758222
## 
## [[360]]
## [1] 8.107111
## 
## [[361]]
## [1] 7.984889
## 
## [[362]]
## [1] 8.292444
## 
## [[363]]
## [1] 6.709333
## 
## [[364]]
## [1] 6.320889
## 
## [[365]]
## [1] 8.94
## 
## [[366]]
## [1] 8.844
## 
## [[367]]
## [1] 8.035111
## 
## [[368]]
## [1] 5.655111
## 
## [[369]]
## [1] 13.93556
## 
## [[370]]
## [1] 5.686667
## 
## [[371]]
## [1] 5.783111
## 
## [[372]]
## [1] 7.333778
## 
## [[373]]
## [1] 6.304
## 
## [[374]]
## [1] 6.685333
## 
## [[375]]
## [1] 6.939556
## 
## [[376]]
## [1] 6.681333
## 
## [[377]]
## [1] 5.937778
## 
## [[378]]
## [1] 5.522222
## 
## [[379]]
## [1] 6.148444
## 
## [[380]]
## [1] 6.930222
## 
## [[381]]
## [1] 6.452444
## 
## [[382]]
## [1] 4.372444
## 
## [[383]]
## [1] 4.698222
## 
## [[384]]
## [1] 4.596444
## 
## [[385]]
## [1] 5.961333
## 
## [[386]]
## [1] 3.471111
## 
## [[387]]
## [1] 4.372889
## 
## [[388]]
## [1] 5.556444
## 
## [[389]]
## [1] 5.204889
## 
## [[390]]
## [1] 5.388
## 
## [[391]]
## [1] 2.397778
## 
## [[392]]
## [1] 4.606222
## 
## [[393]]
## [1] 4.544
## 
## [[394]]
## [1] 4.142667
## 
## [[395]]
## [1] 4.584444
## 
## [[396]]
## [1] 4.920444
## 
## [[397]]
## [1] 3.113333
## 
## [[398]]
## [1] 2.564889
## 
## [[399]]
## [1] 3.728889
## 
## [[400]]
## [1] 3.76
## 
## [[401]]
## [1] 3.991111
## 
## [[402]]
## [1] 4.979111
## 
## [[403]]
## [1] 4.064889
## 
## [[404]]
## [1] 4.063111
## 
## [[405]]
## [1] 2.694222
## 
## [[406]]
## [1] 4.106222
## 
## [[407]]
## [1] 4.148889
## 
## [[408]]
## [1] 4.553778
## 
## [[409]]
## [1] 3.191111
## 
## [[410]]
## [1] 2.656
## 
## [[411]]
## [1] 5.145778
## 
## [[412]]
## [1] 2.593333
## 
## [[413]]
## [1] 3.928889
## 
## [[414]]
## [1] 3.697333
## 
## [[415]]
## [1] 4.693778
## 
## [[416]]
## [1] 4.402222
## 
## [[417]]
## [1] 3.278667
## 
## [[418]]
## [1] 3.469778
## 
## [[419]]
## [1] 4.517778
## 
## [[420]]
## [1] 6.729333
## 
## [[421]]
## [1] 4.061778
## 
## [[422]]
## [1] 3.864444
## 
## [[423]]
## [1] 2.016
## 
## [[424]]
## [1] 1.374667
## 
## [[425]]
## [1] 2.884444
## 
## [[426]]
## [1] 4.185778
## 
## [[427]]
## [1] 3.336889
## 
## [[428]]
## [1] 3.303111
## 
## [[429]]
## [1] 2.512889
## 
## [[430]]
## [1] 3.604889
## 
## [[431]]
## [1] 3.237333
## 
## [[432]]
## [1] 1.766667
## 
## [[433]]
## [1] 2.208889
## 
## [[434]]
## [1] 2.309333
## 
## [[435]]
## [1] 1.569778
## 
## [[436]]
## [1] 1.484444
## 
## [[437]]
## [1] 1.835556
## 
## [[438]]
## [1] 2.141333
## 
## [[439]]
## [1] 1.931556
## 
## [[440]]
## [1] 3.183111
## 
## [[441]]
## [1] 2.870667
## 
## [[442]]
## [1] 4.372889
## 
## [[443]]
## [1] 1.778222
## 
## [[444]]
## [1] 2.929333
## 
## [[445]]
## [1] 3.208444
## 
## [[446]]
## [1] 2.057778
## 
## [[447]]
## [1] 2.393778
## 
## [[448]]
## [1] 1.732889
## 
## [[449]]
## [1] 2.535556
## 
## [[450]]
## [1] 3.170222
## 
## [[451]]
## [1] 1.621778
## 
## [[452]]
## [1] 0.7404444
## 
## [[453]]
## [1] 2.176889
## 
## [[454]]
## [1] 1.967111
## 
## [[455]]
## [1] 1.635111
## 
## [[456]]
## [1] 2.474222
## 
## [[457]]
## [1] 2.739556
## 
## [[458]]
## [1] 1.022222
## 
## [[459]]
## [1] 2.961333
## 
## [[460]]
## [1] 2.452889
## 
## [[461]]
## [1] 1.841333
## 
## [[462]]
## [1] 0.6808889
## 
## [[463]]
## [1] 1.834222
## 
## [[464]]
## [1] 1.570667
## 
## [[465]]
## [1] 0.7697778
## 
## [[466]]
## [1] 1.581778
## 
## [[467]]
## [1] 1.924
## 
## [[468]]
## [1] 1.390667
## 
## [[469]]
## [1] 1.750667
## 
## [[470]]
## [1] 3.524444
## 
## [[471]]
## [1] 2.808
## 
## [[472]]
## [1] 1.777333
## 
## [[473]]
## [1] 2.267111
## 
## [[474]]
## [1] 1.845333
## 
## [[475]]
## [1] 2.391556
## 
## [[476]]
## [1] 1.720889
## 
## [[477]]
## [1] 1.036889
## 
## [[478]]
## [1] 1.139556
## 
## [[479]]
## [1] 2.027111
## 
## [[480]]
## [1] 1.753333
## 
## [[481]]
## [1] 1.938667
## 
## [[482]]
## [1] 2.144889
## 
## [[483]]
## [1] 1.527556
## 
## [[484]]
## [1] 1.174222
## 
## [[485]]
## [1] 1.762222
## 
## [[486]]
## [1] 2.091556
## 
## [[487]]
## [1] 0.6755556
## 
## [[488]]
## [1] 0.5702222
## 
## [[489]]
## [1] 0.9671111
## 
## [[490]]
## [1] 0.9973333
## 
## [[491]]
## [1] 1.089333
## 
## [[492]]
## [1] 1.089778
## 
## [[493]]
## [1] 1.058667
## 
## [[494]]
## [1] 0.7915556
## 
## [[495]]
## [1] 1.720889
## 
## [[496]]
## [1] 0.6115556
## 
## [[497]]
## [1] 0.9893333
## 
## [[498]]
## [1] 1.338222
## 
## [[499]]
## [1] 1.538667
## 
## [[500]]
## [1] 1.986222
## 
## [[501]]
## [1] 1.875556
## 
## [[502]]
## [1] 2.102667
## 
## [[503]]
## [1] 1.632
## 
## [[504]]
## [1] 0.88
## 
## [[505]]
## [1] 2.118222
## 
## [[506]]
## [1] 2.675556
## 
## [[507]]
## [1] 2.651556
## 
## [[508]]
## [1] 0.9933333
## 
## [[509]]
## [1] 1.253333
## 
## [[510]]
## [1] 2.544444
## 
## [[511]]
## [1] 1.666667
## 
## [[512]]
## [1] 2.100889
Spectra = Spectra %>% map(function(x){x %>% unlist %>% return()}) %>% unlist() %>% matrix(byrow = TRUE,ncol = 512) %>% as_tibble()
colnames(Spectra) = 1:512
Spectra$Tag = Tags %>% map(function(x){x %>% unlist %>% return()}) %>% unlist()
Spectra = separate(Spectra,Tag,into = c("camera","light","percent"),sep = "-")
GatheredSpectra = gather(Spectra,"pixel","Value",1:512)

GatheredSpectra$pixel = as.numeric(GatheredSpectra$pixel)
GatheredSpectra$percent = as.numeric(GatheredSpectra$percent)
GatheredSpectra$camera = as.factor(GatheredSpectra$camera)
GatheredSpectra$light = as.factor(GatheredSpectra$light)
#filter(GatheredSpectra,camera == 1) %>% ggplot(aes(pixel,Value,colour = light)) + geom_line() #+ facet_wrap(~light)

GatheredSpectra %>% ggplot(aes(pixel,Value,colour = percent %>% as.factor())) + geom_line() + facet_grid(rows = vars(light),cols = vars(camera))

#PercMean = Spectra %>% group_by(percent) %>% select(-camera,-light) %>%  summarise_all(mean)
#gather(PercMean,pixel,value,2:513) %>% ggplot(aes(pixel %>% as.numeric(),value %>% as.numeric(),colour = as.factor(percent))) + geom_line()

filter(GatheredSpectra,camera == 1,light == 1,pixel == 300) %>% ggplot(aes(Value,percent)) + geom_line() 

nestedSpectra = Spectra %>% group_by(light,camera) %>% nest()
library(pls)
PLSR = function(x){
  model = pls::plsr(percent ~ ., data = x, ncomp = 1, validation = "LOO")
  return(model)
}
models = nestedSpectra$data %>% map(PLSR)
par(mfrow= c(2,5))
for(i in 1:10){
  plot(models[[i]])
}

par(mfrow= c(1,1))